from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from meiduo_mall import settings


def generic_openid_token(openid):

    serializer = Serializer(secret_key=settings.SECRET_KEY,expires_in=3600)
    data  = {"openid":openid}

    token = serializer.dumps(data)

    return token.decode()

def check_access_token(token):

    serializer = Serializer(secret_key=settings.SECRET_KEY, expires_in=3600)
    try:
        data = serializer.loads(token)
    except Exception:
        return None

    openid = data.get("openid")

    return openid

